package com.francis.springbootcommonutil;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * <p>Title: CheckHttpUrl</p>
 * <p>Description: CheckHttpUrl 检查http请求url是否正确</p>
 * <p>Copyright: ChenWei Copyright(c) 2018/p>
 *
 * @author ChenWei
 * @version 0.0.0.1
 * <pre>Histroy:
 *       2020/6/22 14:52 Create by ChenWei
 * </pre>
 */
public class CheckHttpUrl {

    /**
     * @param urls 需要判断的String类型url
     * @return boolean  true:是URL；false:不是URL
     * @methodName isHttpUrl
     * @description 判断字符串是否为URL
     * @author ChenWei
     * @date 2020/6/22 14:54
     */
    public static boolean isHttpUrl(String urls) {
        boolean isUrl = false;
        //设置正则表达式
        String regex = "(((https|http)?://)?([a-z0-9]+[.])|(www.))"
                + "\\w+[.|\\/]([a-z0-9]{0,})?[[.]([a-z0-9]{0,})]+((/[\\S&&[^,;\u4E00-\u9FA5]]+)+)?([.][a-z0-9]{0,}+|/?)";
        //对比
        Pattern pat = Pattern.compile(regex.trim());
        Matcher mat = pat.matcher(urls.trim());
        //判断是否匹配
        isUrl = mat.matches();
        if (isUrl) {
            isUrl = true;
        }
        return isUrl;
    }

}
